#include<iostream>
#include<sys/epoll.h>
#include<string>
#include"Log.hpp"

using namespace LogModule;
class Epoller
{

    public:
    const static int num = 256;
    Epoller()
    :_epfd(-1)
    {
        
    }
    void Init()
    {
        _epfd = epoll_create(num);
        if(_epfd < 0)
        {
            LOG(LogLevel::ERROR)<<"epoll_create errno";
            return ;
        }
        LOG(LogLevel::DEBUG)<<"epoll_create success";
    }
    int Wait(struct epoll_event revs[], int num)
    {
        int n = epoll_wait(_epfd,revs,num,-1);
        if(n < 0 )
        {
            LOG(LogLevel::ERROR)<<"epoll wait false";
            return -1; 
        }
        LOG(LogLevel::DEBUG)<<"epoll wait success";
        return n ;
    }
    void Ctrl(int tmpopotion,int fd,uint32_t tmpevent)
    {
        struct epoll_event revs;
        revs.data.fd = fd;
        revs.events = tmpevent; 
        int n = epoll_ctl(_epfd,tmpopotion,fd,&revs);
        if(n < 0)
        {
            LOG(LogLevel::ERROR)<<"epoll ctl false";
            return;
        }
        LOG(LogLevel::DEBUG)<<"epoll wait success";
    }
    ~Epoller()
    {

    }

    private:
    int _epfd;
};